package com.jingogo.controller;

import com.jingogo.common.Result;
import com.jingogo.entity.Store;
import com.jingogo.service.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/store")
@Tag(name = "门店管理", description = "门店信息管理接口")
public class StoreController {
    @Autowired
    private StoreService storeService;

    @PostMapping("/add")
    @Operation(summary = "添加门店", description = "添加门店信息")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> addStore(@RequestBody Store store) {
        storeService.addStore(store);
        return Result.success("门店添加成功");
    }

    @PutMapping("/edit")
    @Operation(summary = "编辑门店", description = "编辑门店信息")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> editStore(@RequestBody Store store) {
        storeService.editStore(store);
        return Result.success("门店编辑成功");
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除门店", description = "删除门店信息")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> deleteStore(@RequestParam Long storeId) {
        storeService.deleteStore(storeId);
        return Result.success("门店删除成功");
    }

    @GetMapping("/list")
    @Operation(summary = "门店列表", description = "获取门店列表")
    public Result<List<Store>> listStores() {
        return Result.success(storeService.listStores());
    }
} 